package com.iakuil.app.api.controller;


import com.iakuil.app.common.core.BaseController;
import com.iakuil.app.common.core.domain.Result;
import com.iakuil.app.domain.dto.OperationLogDto;
import com.iakuil.app.domain.dto.query.OperationLogQuery;
import com.iakuil.app.service.OperationLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 操作日志接口
 *
 * <p>审计日志包括系统日志与用户日志，前者通过log4j2等工具打印到日志文件，后者记录到数据库。
 * <p>其中用户日志又可以分为会话（登录）日志与操作（业务）日志。
 *
 * @author Kai
 * @date 2023-04-12
 */
@Tag(name = "操作日志", description = "操作日志接口")
@RestController
@RequestMapping("/api/v1/oplog/")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OperationLogController extends BaseController {
    private final OperationLogService operationLogService;

    @Operation(summary = "操作日志列表", description = "分页查询操作日志数据。")
    @PostMapping(value = "/list")
    public Result<OperationLogDto> doQuery(@RequestBody OperationLogQuery param) {
        startPage();
        return pageInfo(operationLogService.listByCondition(param)).map(e -> convert(e, OperationLogDto.class));
    }

    @Operation(summary = "操作日志删除", description = "删除操作日志。")
    @Parameter(name = "id", description = "日志ID", required = true, in = ParameterIn.QUERY)
    @PostMapping(value = "/remove")
    public Result<Void> doRemove(@RequestParam Long id) {
        return success(operationLogService.removeById(id));
    }
}
